Skip to content

repo: Widestring cleanups - #5192

Open
Steven Malis (smalis-msft) wants to merge 2 commits into
microsoft:mainfrom
smalis-msft:widerstrings
Open

Steven Malis (smalis-msft) wants to merge 2 commits into
microsoft:mainfrom
smalis-msft:widerstrings

Conversation

@smalis-msft

Copy link
Copy Markdown
Contributor

Windows wide string requirements are annoying. Use our Ucs2 types and the widestring crate in more places, replacing manual handling and null fixups. Drop the wchr dependency completely, as it's redundant.

@smalis-msft
Steven Malis (smalis-msft) requested review from Chris Oo (chris-oo) and a balanced review from Copilot November 20, 2026 21:26
@github-actions github-actions Bot added the unsafe Related to unsafe code label Nov 20, 2026
@github-actions

Copy link
Copy Markdown

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The bounded RPC string conversion can cause undefined behavior through an out-of-bounds slice, while environment and KVP conversions accept trailing NULs, silently truncating values and allowing KVP key aliases.

3 open issues
What changed in this PR

This PR standardizes wide-string handling across OpenVMM’s Windows interfaces, firmware helpers, and tests, replacing manual encoding and NUL termination with widestring and existing UCS-2 types.

Changes:

  • Replace manual wide-string buffers and literals with typed string helpers.
  • Simplify UTF-16 conversions and add validation and encoding tests.
  • Remove wchar and update affected dependencies.
File Description
vmm_core/​hyperv_dump/​tests/​cross_validate.rs Use typed wide paths for DLL calls.
vmm_core/​hyperv_dump/​Cargo.toml Add widestring for tests.
vm/​whp/​src/​lib.rs Convert PCI instance paths with U16CString.
vm/​whp/​Cargo.toml Add Windows widestring dependency.
vm/​loader/​snp_bootshim/​src/​efi/​tables.rs Compare the complete firmware vendor string.
vm/​devices/​support/​fs/​lxutil/​src/​windows/​util.rs Use typed wide filesystem names.
vm/​devices/​support/​fs/​lxutil/​src/​windows/​symlink.rs Simplify trailing-NUL removal.
vm/​devices/​support/​fs/​lxutil/​src/​windows/​readdir.rs Convert directory names through U16Str.
vm/​devices/​support/​fs/​lxutil/​src/​windows/​mod.rs Simplify colon checks and wide-string test data.
vm/​devices/​storage/​vhdx/​tests/​native_cross_validation.rs Replace manual wide-path helper.
vm/​devices/​storage/​vhdx/​src/​locator.rs Decode UTF-16 without an intermediate vector.
vm/​devices/​storage/​vhdx/​Cargo.toml Add Windows test dependency.
vm/​devices/​storage/​disk_vhdmp/​src/​lib.rs Centralize validated wide-path conversion.
vm/​devices/​storage/​disk_vhdmp/​Cargo.toml Add widestring dependency.
vm/​devices/​net/​netvsp/​src/​lib.rs Use a compile-time wide friendly name.
vm/​devices/​net/​netvsp/​Cargo.toml Add widestring dependency.
vm/​devices/​hyperv_ic/​src/​kvp.rs Use typed NUL-terminated KVP strings.
vm/​devices/​hyperv_ic/​src/​kvp_tests.rs Test string boundaries and malformed input.
vm/​devices/​hyperv_ic/​Cargo.toml Add widestring dependency.
vm/​devices/​get/​test_igvm_agent_rpc_server/​src/​rpc/​server.rs Use static wide RPC identifiers.
vm/​devices/​get/​test_igvm_agent_rpc_server/​src/​rpc/​handlers.rs Replace manual RPC string decoding.
vm/​devices/​get/​test_igvm_agent_rpc_server/​Cargo.toml Add widestring dependency.
vm/​devices/​firmware/​uefi_specs/​src/​uefi/​nvram.rs Clarify literal-generation documentation.
vm/​devices/​firmware/​uefi_specs/​src/​lib.rs Replace wchar literals with widestring.
vm/​devices/​firmware/​uefi_specs/​Cargo.toml Switch optional wide-string dependency.
vm/​devices/​firmware/​uefi_nvram_storage/​src/​in_memory.rs Use UCS-2 types for test names.
vm/​devices/​firmware/​uefi_nvram_storage/​Cargo.toml Remove wchar dependency.
vm/​devices/​firmware/​hcl_compat_uefi_nvram_storage/​src/​lib.rs Convert test names to UCS-2 types.
vm/​devices/​firmware/​hcl_compat_uefi_nvram_storage/​Cargo.toml Remove wchar test dependency.
vm/​devices/​firmware/​firmware_uefi/​src/​service/​nvram/​spec_services/​mod.rs Replace wide literals in NVRAM tests.
vm/​devices/​firmware/​firmware_uefi/​src/​service/​nvram/​mod.rs Use UCS-2 buffers in firmware tests.
vm/​devices/​firmware/​firmware_uefi/​Cargo.toml Remove wchar test dependency.
support/​ucs2/​src/​lib.rs Simplify conversions and test encoding behavior.
support/​pal/​src/​windows/​security.rs Simplify embedded-NUL test input.
support/​pal/​src/​windows/​process.rs Use typed process strings and test environments.
support/​pal/​src/​windows/​fs/​relative.rs Use typed relative names and test surrogate preservation.
support/​pal/​src/​windows.rs Simplify Unicode conversion and extend tests.
support/​hvs_file/​src/​writer.rs Stream UTF-16LE encoding into output.
support/​hvs_file/​src/​reader.rs Remove intermediate UTF-16 decoding allocation.
support/​crypto/​src/​x509/​win.rs Use typed certificate strings and attributes.
support/​crypto/​src/​aes_kwp/​win.rs Borrow the terminated chaining-mode string.
support/​crypto/​src/​aes_256_gcm/​win.rs Borrow the terminated chaining-mode string.
support/​crypto/​Cargo.toml Add Windows widestring dependency.
petri/​make_imc_hive/​src/​windows/​offreg.rs Use typed registry names and values.
petri/​make_imc_hive/​Cargo.toml Add widestring dependency.
openhcl/​underhill_attestation/​src/​jwt.rs Simplify UTF-16 test-data construction.
Cargo.toml Remove workspace wchar dependency.
Cargo.lock Update dependencies and remove wchar packages.

Review effort: Balanced

Comment thread support/pal/src/windows/process.rs Resolved
Comment thread vm/devices/hyperv_ic/src/kvp.rs Resolved
Copilot AI balanced review requested due to automatic review settings November 20, 2026 21:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the wide-string standardization.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants